package com.test.nnooolwdeaer.activity_fragment_wooden.info_wooden;

import android.os.Bundle;
import android.widget.Button;

import com.test.nnooolwdeaer.activity_fragment_wooden.base_wooden.BaseInfoActivity_wooden;
import com.test.nnooolwdeaer.bean_wooden.user_info_wooden.CoteBankAccountList_wooden;
import com.test.nnooolwdeaer.constant_wooden.Url_wooden;
import com.test.nnooolwdeaer.dialog_wooden.SubmitAccountInfoDialog_Cote_wooden;
import com.test.nnooolwdeaer.util_wooden.helper_wooden.UserInfoHelper_wooden;
import com.test.nnooolwdeaer.util_wooden.http_wooden.HttpManager_wooden;
import com.test.nnooolwdeaer.view_wooden.module_wooden.AddBankAccountView_Cote_wooden;
import com.test.nnooolwdeaer.view_wooden.widget_wooden.TitleView_wooden;
import com.test.nnooolwdeaer.R;

import java.util.TreeMap;

public class BindBankAccountActivity_Cote_wooden extends BaseInfoActivity_wooden {

    //private EditText firstNameEt,middleNameEt,lastNameEt;
    private AddBankAccountView_Cote_wooden addBankAccountView_wooden;
    private Button nextBtn_wooden;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bind_bank_account_cote_wooden);
        init_wooden();
    }

    private void init_wooden(){
        TitleView_wooden titleView = findViewById(R.id.activity_bind_bank_account_view_title);
        setBackBtn_wooden(titleView.getBackIb_wooden());

        nextBtn_wooden = findViewById(R.id.activity_bind_bank_account_btn_submit);
        addBankAccountView_wooden = findViewById(R.id.activity_bind_bank_account_view_add_bank_account);

        nextBtn_wooden.setOnClickListener(v -> {
            HttpManager_wooden.getInstance_wooden().saveUserBuriedPointAndUpload("BVN_COMMIT_CLICK");
            if (CoteBankAccountList_wooden.getInstance_wooden().getBankAccountList_wooden().size()==0){//无收款账户：弹窗提示，按键灰态
                showToast_wooden("Veuillez ajouter au moins un compte de réception de prêt valide.");
            }else {//有收款账户且信息已输入：进入下一步流程
                new SubmitAccountInfoDialog_Cote_wooden(this, v1 -> HttpManager_wooden.getInstance_wooden().uploadInfo_wooden(Url_wooden.PATH_BVN_INFO, parseData_wooden())).show();
            }
        });
    }


    private TreeMap<String,String> parseData_wooden() {
        return new TreeMap<String,String>(){{
            put("bvn", UserInfoHelper_wooden.getInstance_wooden().getMobile_wooden());
        }};
    }

    @Override
    protected void onResume() {
        super.onResume();
        HttpManager_wooden.getInstance_wooden().fetchBoundBankAccount_Cote_wooden();
    }

    //添加钱包账户返回
    public void onBindBankAccountResponse_wooden(){
        AddBankAccountView_Cote_wooden.addAccountFlag_wooden = true;
        HttpManager_wooden.getInstance_wooden().fetchBoundBankAccount_Cote_wooden();
    }

    //删除账户返回
    public void onDeleteBankAccountResponse_wooden(){
        showToast_wooden("Supprimé avec succès");
        HttpManager_wooden.getInstance_wooden().fetchBoundBankAccount_Cote_wooden();
    }

    public void onFetchBankAccountListResponse_wooden() {
        addBankAccountView_wooden.updateAccountList_wooden();
    }
}